<%@ LANGUAGE="VBSCRIPT" %>
<%'  ------------------------------------------------------------
  '  mz_advqresult.asp 
  '  ------------------------------------------------------------
  '  VCS INFO:
  '  
  '  $Revision:   1.9  $
  '  $Date:   05 Dec 2000 17:07:02  $
  '  $Author:   syu  $
  '  $Workfile:   mz_advqresult.asp  $
  '  ------------------------------------------------------------
  '  All Rights Reserved.  Copyright (c) 1988-1998 FileNET Corp.
  '  ------------------------------------------------------------
  '%>
<!-- #include file="islogon.asp" -->
<!-- #include file="jscriptfix.asp" -->
<!-- #include file="notimpl.asp" -->

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html">
<TITLE>Query Result</TITLE>
</HEAD>

<BODY bgcolor="#FFFFFF" topmargin="0" leftmargin="0">

<%
set oDocUtil = Server.CreateObject("IDMWeb.DocumentUtilities")

'If we are going to start a new search, reset the ResultPageNumber and bump the ResultID.
If Request.Form("NewSearch") = 1 Then
    Session("ResultPageNumber") = 0
    Session("ResultID") = Session("ResultID") + 1
End If

ResultPageNumber = Session("ResultPageNumber")
if ResultPageNumber = 0 then
    'Build the QueryCommandText
    HiddenQueryCondition = Request.Form("HiddenQueryCondition")

    QueryCommandText = "SELECT idmId,idmName,idmDocType, idmDateAdded,idmAddedByUser FROM FnDocument "
%>

<%
    len1 = Len(HiddenQueryCondition)
%>

<%
    'If the HiddenQueryCondition field is empty, assume the whole query condition is passed in from
    ' a form field of the mz_advqspec.asp
    If len1 = 0 Then
        QueryCommandText = QueryCommandText + Request.Form("QueryCondition")
    Else
        pos1 = InStr(HiddenQueryCondition, "Request('")
        If pos1 Then
            pos2 = 1
            While pos1
%>
<!-- pos1=<%= pos1 %> <br> -->
<%
                QueryCommandText = QueryCommandText + Mid(HiddenQueryCondition, pos2, pos1 - pos2)
                pos1 = pos1 + 9
                pos2 = InStr(pos1, HiddenQueryCondition, "')")
                Var = Mid(HiddenQueryCondition, pos1, pos2 - pos1)
                QueryCommandText = QueryCommandText + Request.Form(Var)
                pos2 = pos2 + 2
                pos1 = InStr(pos2, HiddenQueryCondition, "Request('")
            Wend
            QueryCommandText = QueryCommandText + Right(HiddenQueryCondition, len1 - pos2 + 1)
        Else
            QueryCommandText = QueryCommandText + HiddenQueryCondition
        End If
    End If
    'Keep the QueryCommandText until the next NewSearch = 1.
    Session("QueryCommandText") = QueryCommandText
else
    'Keep using the same QueryCommandText until the next NewSearch = 1.
    QueryCommandText = Session("QueryCommandText")
end if

'Now we can do a search.
set ResultRecordset = Server.CreateObject("ADODB.Recordset")
ResultRecordset.MaxRecords = 200
ResultRecordset.PageSize = 50

'Panagon IDM Web application uses the Session variable LibraryLogonID to keep track of
'whether the user has logged on.
LibraryLogonID = Session("LibraryLogonID")
Set LibraryObject = Server.CreateObject("IDMObjects.Library")
LibraryObject.LogonId = LibraryLogonID

'Setup the connection string and other parameters.
Connect = "provider=FnDBProvider;data source=" + Session("LibraryName") + ";" + _
    "SystemType=" + CStr(LibraryObject.SystemType) + ";LogonID=" + LibraryLogonID + ";Prompt=4;"
%>

<%
set objConnect =  Server.CreateObject("ADODB.Connection")
objConnect.ConnectionString = Connect
objConnect.Open
%>

<!-- %= Connect % -->
<!-- %= QueryCommandText % -->

<%
set ResultRecordset.ActiveConnection = objConnect
ResultRecordset.Properties("SupportsObjSet") = TRUE
ResultRecordset.CursorType = adOpenKeyset

'Execute the search.
On Error Resume Next
ResultRecordset.Open QueryCommandText

if Len(Err.Description) > 0 then %>
<%= Err.Description %>
<SCRIPT LANGUAGE=JavaScript>
<!--
function SubmitAction()
{
parent.location.href = "viewer.asp"
}
//-->
</SCRIPT>


<!-- ResultRecordset.ActiveConnection = Connect -->
<!-- ResultRecordset.Open QueryCommandText, Connect, adOpenKeyset -->


<% else
PageCount = ResultRecordset.PageCount
if ResultPageNumber = 0 then
    'Show the first search results page.
    ResultPageNumber = 1
elseif Len(Request.QueryString("Page")) then
    'Show the specified page.
    ResultPageNumber = CInt(Request.QueryString("Page"))
end if
Session("ResultPageNumber") = ResultPageNumber

ResultPageSize = ResultRecordset.PageSize
ResultCount = ResultRecordset.RecordCount
'Now we can start displaying the search result in a HTML table format
%>

<table width=100%><tr>
<td><strong>[<%= Server.HTMLEncode(Session("LibraryLabel")) %>]:</strong> <font size=2><%= ResultCount %> Document(s) Found ...</font><td>
<% if PageCount > 0 then %>
<td valign=middle align=right><font size=2>Page: <%= ResultPageNumber %> of <%= PageCount %></font></td>
<% end if %>
</tr>
</table>

<form name="DocList" action="viewer.asp" method="GET" target="_top">
<table border=0 cellpadding=0 cellspacing=1 width=100%>
<tr>
<td BGCOLOR=#AAFFAA align=center width=50>&nbsp;</td>
<td BGCOLOR=#AAFFAA align=center width=30>&nbsp;</td>
<td BGCOLOR=#AAFFAA align=left><font size=3><strong>&nbsp;&nbsp;Name&nbsp;&nbsp;</strong></font></td>
<td BGCOLOR=#AAFFAA align=left><font size=3><strong>&nbsp;&nbsp;Item ID&nbsp;&nbsp;</strong></font></td>
<td BGCOLOR=#AAFFAA align=left><font size=3><strong>&nbsp;&nbsp;Document Class&nbsp;&nbsp;</strong></font></td>
<td BGCOLOR=#AAFFAA align=left><font size=3><strong>&nbsp;&nbsp;Date Added&nbsp;&nbsp;</strong></font></td>
<td BGCOLOR=#AAFFAA align=left><font size=3><strong>&nbsp;&nbsp;Author&nbsp;&nbsp;</strong></font></td>
<td BGCOLOR=#AAFFAA align=center width=20>&nbsp;</td>
</tr>
<%
If ResultCount then

'Calculate the index of the first item in the target search result page to display.
prevIndex = (ResultPageNumber - 1) * ResultPageSize
set ResultsCollection = ResultRecordset("ObjSet").Value

'Display a page.
For Count1 = 1 To ResultPageSize
    index = prevIndex + Count1
    if index > ResultCount then
        exit for
    end if
    ResultRecordset.AbsolutePosition = index
    set DocumentObj = ResultsCollection(index)
    DocId = DocumentObj.ID %>
    <tr>
    <td BGCOLOR=#AAFFAA align=right>
    <% if Application("ViewUsingNativeApplication")=false then %>
    <input type="checkbox" name="docid" value="<%= DocId %>">
    <% end if %>
    <font size=2><%= index %>.</font></td>
    <td align=right valign=bottom>
    <% if DocumentObj.GetState(Application("idmDocCheckedOut")) then 
    %>
        <img src="images/docckout.gif" align=bottom border=0 width=20 height=21>
    <% end if %></td>
    
    <% set ResultFields = ResultRecordset.Fields %>
    <td valign=bottom><font size=3>
    <a HREF="javascript:ShowDocument('<%=DocId%>')">
    <img src="<%=oDocUtil.IconFile(DocumentObj)%>" align=bottom border=0 width=32 height=32></a>
    <em><%= Server.HTMLEncode(ResultFields(1)) %></em></font></td>
    <td valign=bottom align=left><font size=2>&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(ResultFields(0)) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
    <td valign=bottom align=left><font size=2>&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(ResultFields(2)) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
    <td valign=bottom align=left><font size=2>&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(ResultFields(3)) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
    <td valign=bottom align=left><font size=2>&nbsp;&nbsp;&nbsp;&nbsp;<%= Server.HTMLEncode(ResultFields(4)) %>&nbsp;&nbsp;&nbsp;&nbsp;</font></td>
    <td valign=bottom><a HREF="javascript:ShowProperty(1,'<%=DocId%>')">
    <img alt="'<%= Server.HTMLEncode(DocumentObj.Label) %>' Properties" src="images/prop.gif" align=bottom border=0 width=16 height=21></a></td>
    </tr>
<%
Next
End If

'Close and free the Recordset.
ResultRecordset.Close
%>
</table>
</form>

<SCRIPT LANGUAGE=JavaScript>
<!--
function SubmitAction()
{
<% if ResultCount > 0 then %>
document.DocList.submit();
<% else %>
parent.location.href = "viewer.asp"
<% end if %>
}

function ShowDocument(docid)
{
  <% if Application("ViewUsingNativeApplication") then %>
    // Document Content retrieval with Native Application viewing
    parent.location.href = "doccontent.asp?DocID=" + docid;
  <% else %>
    parent.location.href = "viewer.asp?DocID=" + docid;
  <% end if %>
}

function ShowProperty(type, ident)
{
parent.location.href = "property.asp?Type=" + type + "&Ident=" + ident;
}

function PagingMove(page)
{
location.href = "mz_advqresult.asp?ResultID=<%=Session("ResultID")%>&Page=" + page;
}
//-->
</SCRIPT>

<hr>
<% 
'Support paging.
if ResultCount > ResultPageSize then %>
<table width=100%><tr>
<td width=100%>
<FORM ACTION="<%= Request.ServerVariables("PATH_INFO") %>" METHOD=POST>
<a href="javascript:PagingMove('1')"><img alt="First Page" src="images/top.gif" align=bottom border=0 width=45 height=33></a>

<% if ResultPageNumber = 1 then %>
<a href="javascript:PagingMove('1')"><img alt="Previous Page" src="images/previous.gif" align=bottom border=0 width=45 height=33></a>
<% else %>
<a href="javascript:PagingMove('<%=ResultPageNumber - 1%>')"><img alt="Previous Page" src="images/previous.gif" align=bottom border=0 width=45 height=33></a>
<% end if %>

<% if ResultPageNumber = PageCount then %>
<a href="javascript:PagingMove('<%=PageCount%>')"><img alt="Next Page" src="images/next.gif" align=bottom border=0 width=45 height=33></a>
<% else %>
<a href="javascript:PagingMove('<%=ResultPageNumber + 1%>')"><img alt="Next Page" src="images/next.gif" align=bottom border=0 width=45 height=33></a>
<% end if %>

<a href="javascript:PagingMove('<%=PageCount%>')"><img alt="Last Page" src="images/bottom.gif" align=bottom border=0 width=45 height=33></a>
</FORM>
</td>
</tr></table>
<% else %>
<FORM ACTION="" METHOD=POST>
</FORM>
<% end if %>

<% end if %>


</BODY>
</HTML>
